﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 职工端
{
    public partial class 商品信息查询 : Form
    {
        string strcon = denglu.strcon;
        DataSet myst = new DataSet();
        SqlDataAdapter myda;
        public 商品信息查询()
        {

            InitializeComponent();

        }

        private void button1_Click(object sender, EventArgs e)
        {
            string a = textBox1.Text;
            SqlConnection con = new SqlConnection(strcon);
            if (comboBox1.Text.Equals("供货商ID"))
            {
                    try
                    {   
                        con.Open();
                        string sqlSel = "select * from Supplier where sid = '" + a + "'";
                        SqlCommand com = new SqlCommand(sqlSel, con);
                        myda = new SqlDataAdapter(com);
                        myst.Tables.Clear();
                        myda.Fill(myst, "Supplier");
                        dataGridView1.DataSource = myst.Tables["Supplier"];
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message.ToString() + "失败");
                }
                finally
                {
                    con.Close();
                }

                if (comboBox1.Text.Equals("货物ID"))
                {
                        try
                        {
                            con.Open();
                            string sqlSel = "select * from Goods where gid = '" + a + "'";
                            SqlCommand com = new SqlCommand(sqlSel, con);
                            myda = new SqlDataAdapter(com);
                            myst.Tables.Clear();
                            myda.Fill(myst, "Goods");
                            dataGridView1.DataSource = myst.Tables["Goods"];
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message.ToString() + "失败");
                        }
                    if (comboBox1.Text=="货物名称")
                    {
                        try
                        {
                            con.Open();
                            string sqlSel = "select * from Goods where gname = '" + a + "'";
                            SqlCommand com = new SqlCommand(sqlSel, con);
                            myda = new SqlDataAdapter(com);
                            myst.Tables.Clear();
                            myda.Fill(myst, "Goods");
                            dataGridView1.DataSource = myst.Tables["Goods"];
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message.ToString() + "失败");
                        }
                    }
                    if (comboBox1.Text == "供货商名称")
                    {
                        try
                        {
                            con.Open();
                            string sql = "select * from Supplier where sid = '" + a + "'";
                            SqlCommand com = new SqlCommand(sql, con);
                            myda = new SqlDataAdapter(com);
                            myst.Tables.Clear();
                            myda.Fill(myst, "Supplier");
                            dataGridView1.DataSource = myst.Tables["Supplier"];
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message.ToString() + "失败");
                        }
                    }
                }
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
            SqlConnection con = new SqlConnection(strcon);
                try
                {
                    con.Open();
                    string sqlSel = "select * from Goods";
                    SqlCommand com = new SqlCommand(sqlSel, con);
                    myda = new SqlDataAdapter(com);
                    myst.Tables.Clear();
                    myda.Fill(myst, "Goods");
                    dataGridView1.DataSource = myst.Tables["Goods"];
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString() + "失败");
                }
            
        }
    }
}

